package com.ruoyi.od_organizer.service.impl;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ruoyi.od.service.impl.OdUserArticleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.od_organizer.mapper.Od_organizer_ActivityMapper;
import com.ruoyi.od_organizer.domain.Od_organizer_Activity;
import com.ruoyi.od_organizer.service.IOd_organizer_ActivityService;

/**
 * 活动发布Service业务层处理
 * 
 * @author 榛子
 * @date 2023-07-29
 */
@Service
public class Od_organizer_ActivityServiceImpl implements IOd_organizer_ActivityService 
{
    @Autowired
    private Od_organizer_ActivityMapper od_organizer_ActivityMapper;

    /**
     * 查询活动发布
     * 
     * @param id 活动发布主键
     * @return 活动发布
     */
    @Override
    public Od_organizer_Activity selectOd_organizer_ActivityById(Long id)
    {
        return od_organizer_ActivityMapper.selectOd_organizer_ActivityById(id);
    }

    /**
     * 查询活动发布列表
     * 
     * @param od_organizer_Activity 活动发布
     * @return 活动发布
     */
    @Override
    public List<Od_organizer_Activity> selectOd_organizer_ActivityList(Od_organizer_Activity od_organizer_Activity)
    {
        return od_organizer_ActivityMapper.selectOd_organizer_ActivityList(od_organizer_Activity);
    }

    /**
     * 新增活动发布
     * 
     * @param od_organizer_Activity 活动发布
     * @return 结果
     */
    @Override
    public int insertOd_organizer_Activity(Od_organizer_Activity od_organizer_Activity)
    {
        String contentWithoutTags = OdUserArticleServiceImpl.HTMLUtils.removeTags(od_organizer_Activity.getContent());
        od_organizer_Activity.setContent(contentWithoutTags);
        return od_organizer_ActivityMapper.insertOd_organizer_Activity(od_organizer_Activity);
    }

    /**
     * 修改活动发布
     * 
     * @param od_organizer_Activity 活动发布
     * @return 结果
     */
    @Override
    public int updateOd_organizer_Activity(Od_organizer_Activity od_organizer_Activity)
    {
        return od_organizer_ActivityMapper.updateOd_organizer_Activity(od_organizer_Activity);
    }

    /**
     * 批量删除活动发布
     * 
     * @param ids 需要删除的活动发布主键
     * @return 结果
     */
    @Override
    public int deleteOd_organizer_ActivityByIds(Long[] ids)
    {
        return od_organizer_ActivityMapper.deleteOd_organizer_ActivityByIds(ids);
    }

    /**
     * 删除活动发布信息
     * 
     * @param id 活动发布主键
     * @return 结果
     */
    @Override
    public int deleteOd_organizer_ActivityById(Long id)
    {
        return od_organizer_ActivityMapper.deleteOd_organizer_ActivityById(id);
    }
    public class HTMLUtils {
        public static String removeTags(String html) {
            // 定义 HTML 标签的正则表达式
            String pattern = "<[^>]*>";
            // 创建 Pattern 对象
            Pattern p = Pattern.compile(pattern);
            // 创建 Matcher 对象
            Matcher m = p.matcher(html);
            // 使用 replaceAll() 方法替换所有匹配的标签为空字符串
            String result = m.replaceAll("");
            return result;
        }
    }
}
